tableDate = readtable('附件.xlsx');
B = table2array(tableDate);
[r,c] = size(B);%计算行数
tableDate2 = readtable('太阳高度角.xlsx');

%%
%太阳赤纬角：
E = [306;337;0;31;61;92;122;153;184;214;245;275];
for i = 1:size(E,1)
    for j = 1
        element = E(i,j);
        delta = calculateSolarDeclination(element);
        F(i,1)=delta;
    end
end
%fprintf('太阳赤纬角为: %f度\n', F)
%%
%太阳时角：
AA = [9,10.5,12,13.5,15];
for i = 1:size(AA,1)
    for j = 1:size(AA,2)
        zanshi = AA(i,j);
        time(i,j) = (pi/12.*(zanshi-12));
        time1(i,j) = rad2deg(time(i,j));
    end
end
%fprintf('太阳时角：%f\n',time1);
%%
%太阳方位角：
add = zeros(12,4);
%F = [F,add];
Untitled1 = table2array(Untitled);
for i = 1:size(Untitled1,1)
    for j = 1:size(Untitled1,2)
      azimuth(i,j) = real(acos((sin(F(i,j))-sin(Untitled1(i,j)))*sin(deg2rad(39.4)))/(cos(Untitled1(i,j))*cos(deg2rad(39.4))));
    end
end
%fprintf('太阳方位角：%f\n',(azimuth));
%%
%太阳高度角
high = zeros(1,5);
%time2(12,5) = reshape(time1,12,5);
for i = 1:size(time1,1)
   for j = 1:size(time1,2)
        high(i,j) = calculateHigh(time1(i,j),F);
  end
end
%fprintf('太阳高度角：%f\n',high);
%%
function delta = calculateSolarDeclination(element)
    epsilon = (23.45); 
    sinDelta = sin(2 .* pi.* element / 365) .* sin(2.*pi.*(epsilon)/360);
    delta = rad2deg(asin(sinDelta)) ;% 将结果转换为度
end
%%
%计算高度角的函数
function High = calculateHigh(shijian,F)
linshi = deg2rad(39.4);
   bb = deg2rad(F(2,1));
   aa = deg2rad(shijian);
   High1 = cos(bb).*cos(linshi).*cos(aa)+sin(bb).*sin(linshi);
 High =rad2deg(asin(High1));
end

